home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / NewsBase / Source / pswraps.psw < prev    next >
Text File  |  1993-01-12  |  10KB  |  310 lines

  1. defineps initDrag(float mouseDownX, mouseDownY, offsetX, offsetY, imageW,
  2.           imageH | int *iWindow, *bgWindow, *niWindow, *igstate,
  3.           *bggstate, *nigstate, *gWindow, *ggstate)
  4.  
  5.   % compute the image window's starting origin
  6.   /currentX mouseDownX offsetX sub def
  7.   /currentY mouseDownY offsetY sub def
  8.   
  9.   % create a window to hold the image sover the background and save its gstate
  10.   /newImageWindow 50.0 0.0 imageW imageH Retained window def
  11.   newImageWindow windowdeviceround 
  12.   /newImageGs gstate def
  13.   
  14.   % create a window to hold the old background and save its gstate
  15.   /backgroundWindow 100.0 0.0 imageW imageH Retained window def
  16.   backgroundWindow windowdeviceround 
  17.   /backgroundGs gstate def
  18.   
  19.   % get the bits under the imagewindow's imminent location (using the 
  20.   % set autofill false trick)
  21.   /grabWindow currentX currentY imageW imageH Nonretained window def
  22.   false grabWindow setautofill
  23.   Above 0 grabWindow orderwindow
  24.   grabWindow windowdeviceround /grabGstate gstate def
  25.   
  26.   % copy the bits taken from the grabwindow into the bgImage window
  27.   backgroundGs setgstate
  28.   0.0 0.0 imageW imageH grabGstate 0.0 0.0 Copy composite
  29.     
  30.   % remove the grabwindow from the window list;  note: since the grab window's
  31.   % nonretained, ordering it out causes it to forget its current image;  the
  32.   % next time we order it into the window list, it'll do the screen grab trick
  33.   % again
  34.   Out 0 grabWindow orderwindow
  35.   
  36.   % create the window the user will actually drag around
  37.   /imageWindow currentX currentY imageW imageH Retained window def
  38.   imageWindow windowdeviceround 
  39.   /imageGstate gstate def
  40.   
  41.   % the backgroundWindow and imageWindow contain the same images at the start
  42.   0.0 0.0 imageW imageH backgroundGs 0.0 0.0 Copy composite
  43.   
  44.   % bring the imageWindow onscreen (above the window the user clicked upon)
  45.   Above currentX currentY Above 0 findwindow pop 3 1 roll pop pop
  46.   dup currentwindowlevel /windowLevel exch def
  47.   windowLevel imageWindow setwindowlevel
  48.   imageWindow orderwindow
  49.   
  50.   % put the background and grab windows in the same tier
  51.   windowLevel backgroundWindow setwindowlevel
  52.   windowLevel grabWindow setwindowlevel
  53.   
  54.   % pass the window numbers back to the Transparent Window
  55.   imageWindow iWindow
  56.   backgroundWindow bgWindow
  57.   newImageWindow niWindow
  58.   
  59.   % this routine places an object in the first available spot in the UserArray
  60.   /mydefineuserobject { %def
  61.       /uoindex UserObjects length def
  62.       uoindex 1 sub -1 0 { %for
  63.           dup UserObjects exch get null eq
  64.         { /uoindex exch def exit } { pop } ifelse
  65.       } for
  66.       uoindex exch defineuserobject uoindex
  67.   } bind def
  68.   
  69.   % place the gstates in the UserArray and pass the user object numbers back
  70.   % to the TransWindow object
  71.   imageGstate mydefineuserobject igstate
  72.   backgroundGs mydefineuserobject bggstate
  73.   newImageGs mydefineuserobject nigstate
  74.   grabGstate mydefineuserobject ggstate
  75.   
  76.   grabWindow gWindow
  77.   
  78. endps
  79.  
  80.  
  81.  
  82. defineps dragWindow(int imageWindow, newImageWindow, grabWindow, winUnderMouse,
  83.             prevWinUnderMouse;  userobject imageGstate, oldBgGs,
  84.             newImageGs, bitmapGstate, grabGstate;
  85.             float mouseDownX, mouseDownY, offsetX, offsetY, imageW,
  86.             imageH | boolean *mouseup; int *underwindow;
  87.             float *newMouseX, *newMouseY)
  88.  
  89.   /winchanged winUnderMouse 0 ne prevWinUnderMouse 0 ne or def
  90.   /windowUM winUnderMouse def
  91.   /prevwindowUM prevWinUnderMouse def
  92.   
  93.   /lastX mouseDownX def
  94.   /lastY mouseDownY def
  95.   
  96.   { %loop
  97.   
  98.       % get the current mouse location
  99.       /currentX 0 currentmouse /currentY exch def def
  100.       
  101.       % change the image window's contents if the mouse moved or the
  102.       % window in back of the imagewindow has changed its image
  103.       lastX currentX eq lastY currentY eq and not winchanged or { %ifelse
  104.       
  105.       % compute the image window's new location
  106.       /imageX currentX offsetX sub def
  107.       /imageY currentY offsetY sub def
  108.       
  109.       % move the grab window to the new location and grab screen bits under
  110.       % that window's position by bringing it into the window list
  111.       imageX imageY grabWindow movewindow
  112.       Above imageWindow grabWindow orderwindow
  113.       
  114.       % setup to draw into the image buffer
  115.       imageX imageY newImageWindow movewindow
  116.       newImageGs setgstate
  117.  
  118.       winchanged { %ifelse
  119.       
  120.           % the window(s) under the image window changed its contents;
  121.           % since the screen grab trick above can't capture the bits below
  122.           % the image window, we need to do our own screen grab
  123.           
  124.           /saveobj save def
  125.           
  126.           % fill the window with the gray background (workspace window)
  127.           .333 setgray 0.0 0.0 imageW imageH rectfill
  128.           
  129.           % get a list of the windows on screen
  130.           0 countscreenlist array 0 screenlist /warray exch def
  131.           0 countscreenlist 1 sub -1 0 { %for
  132.           
  133.               warray exch get /awindow exch def
  134.           awindow imageWindow eq { exit } if
  135.           imageX imageY gsave awindow windowdeviceround screentobase
  136.             imageW imageH gstate grestore 0.0 0.0 Copy composite
  137.           
  138.           } for
  139.           
  140.           currentdict /awindow undef
  141.           currentdict /warray undef
  142.  
  143.           saveobj restore
  144.           /winchanged false def
  145.         
  146.       }{ %else
  147.           % copy the bits taken from the grabwindow into the cache
  148.           0.0 0.0 imageW imageH grabGstate 0 0 Copy composite
  149.         
  150.           % take the background image from the last drag, shift it over the
  151.           % same amount the mouse moved and copy an bits still remaining
  152.           % into the new background image (giving us the complete image
  153.           % under the image window's new location)
  154.           0.0 0.0 imageW imageH oldBgGs
  155.         lastX currentX sub lastY currentY sub Copy composite
  156.       
  157.       } ifelse
  158.         
  159.       % save the complete background image for next time
  160.       oldBgGs setgstate 0.0 0.0 imageW imageH newImageGs 0 0 Copy composite
  161.       
  162.       % composite the image window's image over the background
  163.       newImageGs setgstate
  164.       0.0 0.0 imageW imageH bitmapGstate 0 0 Sover composite
  165.       
  166.       % save the current point for next time
  167.       /lastX currentX def
  168.       /lastY currentY def
  169.     
  170.       % flush new drawing to the screen (these windows are or were
  171.       % previously under the imagewindow and their images changed;  their
  172.       % flushWindow was disabled so we could flush just before bringing
  173.       % the new image window's image on screen)
  174.       windowUM 0 ne { %if
  175.           gsave windowUM windowdeviceround flushgraphics grestore
  176.           /windowUM 0 def
  177.       } if
  178.       prevwindowUM 0 ne { %if
  179.           gsave prevwindowUM windowdeviceround flushgraphics grestore
  180.           /prevwindowUM 0 def
  181.       } if
  182.       
  183.       % copy the new image to the grab window
  184.       grabGstate setgstate 0.0 0.0 imageW imageH newImageGs 0.0 0.0 Copy
  185.         composite 
  186.       
  187.       % move the image window under the grabwindow
  188.       imageX imageY imageWindow movewindow
  189.       
  190.       % finally, copy the new image into the image window
  191.       imageGstate setgstate
  192.       0.0 0.0 imageW imageH newImageGs 0.0 0.0 Copy composite
  193.     
  194.       % get rid of the grab window
  195.       Out 0 grabWindow orderwindow
  196.  
  197.       buttondown not mouseup exit
  198.       
  199.       }{ %else
  200.       
  201.       buttondown not { %if
  202.       
  203.           % mouseup, so flush unflushed images to screen
  204.           windowUM 0 ne { %if
  205.           gsave windowUM windowdeviceround flushgraphics grestore
  206.           } if
  207.           prevwindowUM 0 ne { %if
  208.           gsave prevwindowUM windowdeviceround flushgraphics grestore
  209.           } if
  210.     
  211.           true mouseup exit
  212.       
  213.     } if
  214.       } ifelse
  215.       
  216.   } bind loop
  217.   
  218.   % find window below mouse location and return it if it's in our context
  219.   currentX currentY Below imageWindow findwindow
  220.   4 1 roll /windowbelow exch def pop pop { %if
  221.       windowbelow currentowner currentcontext eq { %ifelse
  222.       windowbelow underwindow
  223.       }{ %else
  224.       0 underwindow
  225.       } ifelse
  226.   } if
  227.     
  228.   currentX newMouseX
  229.   currentY newMouseY
  230.  
  231. endps
  232.  
  233.  
  234. defineps miniDragWindow(int imageWindow, newImageWindow, grabWindow;
  235.             userobject imageGstate, oldBgGs, newImageGs,
  236.             bitmapGstate, grabGstate;
  237.             float currentX, currentY, offsetX, offsetY, imageW,
  238.             imageH)
  239.   
  240.     % compute the image window's new location
  241.     /imageX currentX offsetX sub def
  242.     /imageY currentY offsetY sub def
  243.  
  244.     % create a window at the new location and grab screen bits under that
  245.     % window's position by bringing it into the window list
  246.     imageX imageY grabWindow movewindow
  247.     Above imageWindow grabWindow orderwindow
  248.  
  249.     % setup to draw into the image buffer
  250.     imageX imageY newImageWindow movewindow
  251.     newImageGs setgstate
  252.  
  253.     % copy the bits taken from the grabwindow into the cache
  254.     0.0 0.0 imageW imageH grabGstate 0.0 0.0 Copy composite
  255.     
  256.     % take the background image from the last drag, shift it over the
  257.     % same amount the mouse moved and copy an bits still remaining
  258.     % into the new background image (giving us the complete image
  259.     % under the image window's new location)
  260.     0.0 0.0 imageW imageH oldBgGs
  261.     lastX currentX sub lastY currentY sub Copy composite
  262.  
  263.     % save the complete background image for next time
  264.     oldBgGs setgstate 0.0 0.0 imageW imageH newImageGs 0.0 0.0 Copy composite
  265.     
  266.     % composite the image window's image over the background
  267.     newImageGs setgstate
  268.     0.0 0.0 imageW imageH bitmapGstate 0.0 0.0 Sover composite
  269.  
  270.     % copy the new image to the grab window
  271.     grabGstate setgstate 0.0 0.0 imageW imageH newImageGs 0.0 0.0 Copy
  272.     composite 
  273.     
  274.     % move the image window under the grabwindow
  275.     imageX imageY imageWindow movewindow
  276.     
  277.     % finally, copy the new image into the image window
  278.     imageGstate setgstate
  279.     0.0 0.0 imageW imageH newImageGs 0.0 0.0 Copy composite
  280.     
  281.     % get rid of the grab window
  282.     Out 0 grabWindow orderwindow
  283.     
  284. endps
  285.  
  286. defineps cleanup(int imageWin, bgWin, newImageWin, grabWin, igstate,
  287.          bggstate, nigstate, ggstate)
  288.          
  289.   % zero out the gstates
  290.   gsave nulldevice
  291.     igstate execuserobject currentgstate pop
  292.     bggstate execuserobject currentgstate pop
  293.     nigstate execuserobject currentgstate pop
  294.     ggstate execuserobject currentgstate pop
  295.   grestore  
  296.   % get rid of the gstates' userarray entries
  297.   igstate undefineuserobject
  298.   bggstate undefineuserobject
  299.   nigstate undefineuserobject
  300.   ggstate undefineuserobject
  301.  
  302.   % destroy the image and cache windows
  303.   imageWin termwindow
  304.   bgWin termwindow
  305.   newImageWin termwindow
  306.   grabWin termwindow
  307.  
  308. endps
  309.  
  310.